package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.entity.Quality;
import com.baomidou.springboot.mapper.QualityMapper;
import com.baomidou.springboot.service.QualityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 关于我们 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class QualityServiceImpl implements QualityService {

    @Autowired
    private QualityMapper qualityMapper;

    @Override
    public void save(Quality quality) {
        quality.setCreateDate(new Date());
        qualityMapper.insert(quality);
    }

    @Override
    public void delete(String id) {
        qualityMapper.deleteById(id);
    }

    @Override
    public Quality edit(String id) {
        return qualityMapper.selectById(id);
    }

    @Override
    public void update(Quality quality) {
        quality.setModifyDate(new Date());
        qualityMapper.updateById(quality);
    }

    @Override
    public Quality view(String id) {
        return qualityMapper.selectById(id);
    }

    @Override
    public Page<Quality> list(Page<Quality> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Quality> qualityList = qualityMapper.findByDateDesc(page, search);
        page.setRecords(qualityList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        qualityMapper.deleteBatchIds(ids);
    }

    @Override
    public Quality findById(String id) {
        return qualityMapper.selectById(id);
    }

    @Override
    public List<Quality> findBySort() {
        return qualityMapper.findBySort();
    }
}
